package com.smfx.yxt.controller.teacher;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smfx.yxt.common.AppUser;
import com.smfx.yxt.common.Const;
import com.smfx.yxt.common.RspResult;
import com.smfx.yxt.common.enums.Status;
import com.smfx.yxt.controller.BaseController;
import com.smfx.yxt.model.TeacherOrderFood;
import com.smfx.yxt.reqVo.TeacherOrderFoodReqVO;
import com.smfx.yxt.service.ITeacherOrderFoodService;
import com.smfx.yxt.utils.DateUtil;

@RequestMapping(Const.TEACHER_ROLE + "/order/food")
@Controller
public class TeacherOrderFoodController extends BaseController {

	@Autowired
	private ITeacherOrderFoodService teacherOrderFoodService;
	
	@RequestMapping(value = {"/",""})
	public String index() {
		return "teacher/orderFood/index";
	}
	
	@RequestMapping("manage")
	public String manage() {
		return "teacher/orderFood/manage";
	}
	
	@RequestMapping("queryDateOrder")
	@ResponseBody Object queryDateOrder(TeacherOrderFoodReqVO vo) {
		AppUser appUser = getAppUser();
		vo.setTeacherId(appUser.getTeacher().getId());
		List<TeacherOrderFood> list = teacherOrderFoodService.selectTeacherListByDate(vo);
		return list;
	}
	
	@RequestMapping("totalDateOrder")
	@ResponseBody Object totalDateOrder(String orderDate) {
		return teacherOrderFoodService.selectTotalByDate(orderDate);
	}

	@RequestMapping("queryOrderList")
	@ResponseBody Object queryOrderList(TeacherOrderFoodReqVO vo) {
		vo.setRows(Integer.MAX_VALUE - 1);
		return teacherOrderFoodService.selectOrderListByParam(vo);
	}
	
	@RequestMapping("orderSubmit")
	@ResponseBody Object orderSubmit(String orderType) {
		try {
			AppUser appUser = getAppUser();
			TeacherOrderFood record = new TeacherOrderFood();
			record.setTeacherId(appUser.getTeacher().getId());
			record.setTeacherName(appUser.getTeacher().getName());
			record.setOrderType(orderType);
			record.setOrderDate(DateUtil.dateToStr(DateUtil.addDay(1),DateUtil.DEFAULT_DATE_FORMAT3));
			teacherOrderFoodService.insertSelective(record);
			return new RspResult(Status.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new RspResult(Status.SUCCESS);
	}
	
	@RequestMapping("orderCancel")
	@ResponseBody Object orderCancel(Integer id) {
		try {
			TeacherOrderFood record = new TeacherOrderFood();
			record.setId(id);
			record.setIsValid(0);
			record.setOrderCancelTime(new Date());
			teacherOrderFoodService.updateByPrimaryKeySelective(record);
			return new RspResult(Status.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new RspResult(Status.SUCCESS);
	}
}
